package com.readbook.service;

import com.readbook.dao.SjglDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SjglService {
    @Autowired
    private SjglDao sjglDao;


    public List<Map<String, Object>> getChildClass(String pid) {
        List<Map<String, Object>> list1 = sjglDao.getChildClass(pid);
        return list1;
    }

    public List<Map<String, Object>> Search_book(Map<String, Object> gmap) {
        List<Map<String, Object>> list1 = sjglDao.Search_book(gmap);
        return list1;
    }


    public Map<String, Object> del_book(Map<String, Object> gmap) {
        Map<String, Object> smap = new HashMap<>();
        //查询该书籍是否已经有人制定读书计划
        List<Map<String, Object>> list1 = sjglDao.list_bookplanByBid(gmap);
        if (list1.size() > 0) {
            smap.put("result", false);
            smap.put("msg", "该书籍已经有同学制定了读书计划,不能删除!");
        } else {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
            gmap.put("jlscsj", df.format(new Date()));
            gmap.put("jlsczt", "1");
            sjglDao.del_book(gmap);
            smap.put("result", true);
            smap.put("msg", "删除成功!");
        }
        return smap;
    }

    public int InsertBook(Map<String, Object> gmap) {
        return sjglDao.InsertBook(gmap);
    }

    public int EditBook(Map<String, Object> gmap) {
        return sjglDao.EditBook(gmap);
    }


    public int insert_bookquestion(Map<String, Object> gmap) {
        //查询最大序号
        int xh = sjglDao.getXh_bookquestion(gmap);
        gmap.put("xh", (xh + 1) + "");
        return sjglDao.insert_bookquestion(gmap);
    }


    public List<Map<String, Object>> Search_Tm(Map<String, Object> gmap) {
        List<Map<String, Object>> list1 = sjglDao.Search_Tm(gmap);
        return list1;
    }

    public int EditBookQuestion(Map<String, Object> gmap) {
        return sjglDao.EditBookQuestion(gmap);
    }


    public int del_bookquestion(Map<String, Object> gmap) {
        return sjglDao.del_bookquestion(gmap);
    }


    public List<Map<String, Object>> Search_bookBySh(Map<String, Object> gmap) {
        List<Map<String, Object>> list1 = sjglDao.Search_bookBySh(gmap);
        return list1;
    }


    public List<Map<String, Object>> Search_XdthByBid(Map<String, Object> gmap) {
        List<Map<String, Object>> list1 = sjglDao.Search_XdthByBid(gmap);
        for (int i = 0; i < list1.size(); i++) {
            Map<String, Object> maps = list1.get(i);
            String learnid = maps.get("LEARNID").toString();
            Map<String, Object> smap = new HashMap<String, Object>();
            smap.put("learnid", learnid);
            List<Map<String, Object>> pics = sjglDao.getListPicsBylearnid(smap);
            maps.put("pics", pics);
        }
        return list1;
    }


    public int xdthSh(Map<String, Object> gmap) {
        return sjglDao.xdthSh(gmap);
    }


    public List<Map<String, Object>> Search_bookPlByBid(Map<String, Object> gmap) {
        List<Map<String, Object>> list1 = sjglDao.Search_bookPlByBid(gmap);
        return list1;
    }


    public int dicussSh(Map<String, Object> gmap) {
        return sjglDao.dicussSh(gmap);
    }


}


